import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    CreateDateColumn,
    UpdateDateColumn,
    ManyToOne,
    JoinColumn
} from 'typeorm';
import { User } from '../../users/entities/user.entity';

export type OtcSide = 'buy' | 'sell';
export type OtcStatus = 'open' | 'partial' | 'filled' | 'canceled' | 'expired';

@Entity('otc_orders')
export class OtcOrder {
    @PrimaryGeneratedColumn()
    id: number;

    @ManyToOne(() => User, (user) => user.orders, { eager: true })
    @JoinColumn({ name: 'user_id' })
    user: User;

    @Column({ type: 'enum', enum: ['buy', 'sell'] })
    side: OtcSide;

    @Column()
    symbol: string; // e.g., 'RWA-001', 'SOLAR-001'

    @Column({ type: 'decimal', precision: 20, scale: 8 })
    price: string;

    @Column({ type: 'decimal', precision: 20, scale: 8 })
    amount: string;

    @Column({ type: 'decimal', precision: 20, scale: 8, default: 0 })
    filledAmount: string;

    @Column({ type: 'enum', enum: ['open', 'partial', 'filled', 'canceled', 'expired'], default: 'open' })
    status: OtcStatus;

    @Column({ nullable: true })
    expiresAt?: Date;

    @Column({ type: 'text', nullable: true })
    notes?: string;

    @CreateDateColumn()
    createdAt: Date;

    @UpdateDateColumn()
    updatedAt: Date;
}
